#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t;
void solve(){
	ll l,r;
	cin>>l>>r;
	auto cal = [&](ll n){
		ll ret=n;
		ret-=n/2;
		ret-=n/3;
		ret-=n/5;
		ret-=n/7;
		
		ret+=n/6;
		ret+=n/10;
		ret+=n/14;
		ret+=n/15;
		ret+=n/21;
		ret+=n/35;
		
		ret-=n/(2*3*5);
		ret-=n/(2*3*7);
		ret-=n/(2*5*7);
		ret-=n/(3*5*7);
		
		ret+=n/(2*3*5*7); 
		return ret;
	};
	cout<<cal(r)-cal(l-1)<<endl;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		solve();
	}	
	
	return 0;
}
